/**
 * Created by root on 2017/9/22.
 */

layui.config({
    base: '/static/js/layuiModulesEX/'
});
layui.use(['paging', 'form', 'layer','formverify'], function () {
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        form = layui.form(),
        formverify = layui.formverify;
    var counter=1;
    var schoolAdminUser = {};
    //分页组件
    var a=true;
    paging.init({
        openWait: true,
        url: '/university/findUniversityAndSchoolsByCondition2',
        elem: '#content', //内容容器
        params: { //发送到服务端的参数
        },
        contentType: "application/json; charset=utf-8",
        type: 'POST',
        tempElem: '#tpl', //模块容器
        pageConfig: { //分页参数配置
            elem: '#paged', //分页容器
            pageSize:1//分页大小
        },
        success: function () { //渲染成功的回调
            //alert('渲染成功');
            console.log("success");
        },
        fail: function (msg) { //获取数据失败的回调
            //alert('获取数据失败')   window.location.reload();
        },
        complate: function () { //完成的回调
            $("#treetable").treetable({
                expandable: true,// 展示
                initialState :"expanded",//默认打开所有节点
                stringCollapse:'关闭',
                stringExpand:'展开',
                onNodeExpand: function() {// 分支展开后的回调函数
                    var node = this;
                    //判断当前节点是否已经拥有子节点
                    var childSize = $("#treetable").find("[data-tt-parent-id='" + node.id + "']").length;
                    if (childSize > 0) {
                        return;
                    }
                    var data = "pageId=" + node.id;
                    // Render loader/spinner while loading 加载时渲染
                    $.ajax({
                        loading : false,
                        sync: false,// Must be false, otherwise loadBranch happens after showChildren?
                        url : context + "/document/loadChild.json",
                        data: data,
                        success:function(result) {
                            if(0 == result.code ){
                                if(!com.isNull(result.body)){
                                    if(0 == eval(result.body['chilPages']).length){//不存在子节点
                                        var $tr = $("#treetable").find("[data-tt-id='" + node.id + "']");
                                        $tr.attr("data-tt-branch","false");// data-tt-branch 标记当前节点是否是分支节点，在树被初始化的时候生效
                                        $tr.find("span.indenter").html("");// 移除展开图标
                                        return;
                                    }

                                    var rows = this.getnereateHtml(result.body['chilPages']);
                                    $("#treetable").treetable("loadBranch", node, rows);// 插入子节点
                                    $("#treetable").treetable("expandNode", node.id);// 展开子节点
                                }
                            }else{
                                alert(result.tip);
                            }
                        }
                    });
                }
            });

        }
    });

})

